package co.yixiang.yshop.module.crm.controller.admin.crmworkwxconfig;

import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import jakarta.validation.constraints.*;
import jakarta.validation.*;
import jakarta.servlet.http.*;
import java.util.*;
import java.io.IOException;

import co.yixiang.yshop.framework.common.pojo.PageParam;
import co.yixiang.yshop.framework.common.pojo.PageResult;
import co.yixiang.yshop.framework.common.pojo.CommonResult;
import co.yixiang.yshop.framework.common.util.object.BeanUtils;
import static co.yixiang.yshop.framework.common.pojo.CommonResult.success;

import co.yixiang.yshop.framework.excel.core.util.ExcelUtils;

import co.yixiang.yshop.framework.apilog.core.annotation.ApiAccessLog;
import static co.yixiang.yshop.framework.apilog.core.enums.OperateTypeEnum.*;

import co.yixiang.yshop.module.crm.controller.admin.crmworkwxconfig.vo.*;
import co.yixiang.yshop.module.crm.dal.dataobject.crmworkwxconfig.CrmWorkWxConfigDO;
import co.yixiang.yshop.module.crm.service.crmworkwxconfig.CrmWorkWxConfigService;

@Tag(name = "管理后台 - 企业微信配置")
@RestController
@RequestMapping("/crm/work-wx-config")
@Validated
public class CrmWorkWxConfigController {

    @Resource
    private CrmWorkWxConfigService workWxConfigService;

    @PostMapping("/create")
    @Operation(summary = "创建企业微信配置")
    @PreAuthorize("@ss.hasPermission('crm:work-wx-config:create')")
    public CommonResult<Integer> createWorkWxConfig(@Valid @RequestBody CrmWorkWxConfigSaveReqVO createReqVO) {
        return success(workWxConfigService.createWorkWxConfig(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新企业微信配置")
    @PreAuthorize("@ss.hasPermission('crm:work-wx-config:update')")
    public CommonResult<Boolean> updateWorkWxConfig(@Valid @RequestBody CrmWorkWxConfigSaveReqVO updateReqVO) {
        workWxConfigService.updateWorkWxConfig(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除企业微信配置")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('crm:work-wx-config:delete')")
    public CommonResult<Boolean> deleteWorkWxConfig(@RequestParam("id") Integer id) {
        workWxConfigService.deleteWorkWxConfig(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得企业微信配置")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('crm:work-wx-config:query')")
    public CommonResult<CrmWorkWxConfigRespVO> getWorkWxConfig(@RequestParam("id") Integer id) {
        CrmWorkWxConfigDO workWxConfig = workWxConfigService.getWorkWxConfig(id);
        return success(BeanUtils.toBean(workWxConfig, CrmWorkWxConfigRespVO.class));
    }



}